/************************* 版本声明 *********************************
 *@since jdk1.5
 *@version 0.1
 ************************* 变更记录 *********************************
 *
 * 创建者：bijiqiang Email:bijiqiang@gmail.com   创建日期： 2010-1-5
 * 创建记录：创建类结构。
 *************************  描 述 *********************************
 * 
 ******************************************************************
 */
package com.realgodo.site.web.admin.candid;

import javax.annotation.Resource;

import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;
import org.springframework.context.annotation.Scope;
import org.springside.modules.orm.Page;

import com.realgodo.site.entity.site.Candid;
import com.realgodo.site.service.site.CandidManager;
import com.realgodo.site.web.admin.AdminDefaultController;

@Scope("prototype")
@Results( { @Result(name = "toindex", type = "redirect", location = "${base}/admin/candid/") })
public class IndexController extends AdminDefaultController {

	private static final long serialVersionUID = 7545936754537692753L;

	@Resource
	private CandidManager candidManager;

	private Candid candid;

	private Page<Candid> candidPage = new Page<Candid>(PAGE_SIZE);

	public String execute() {
		candidPage.setPageNo(candidManager.isParamNotNull(getParamMap(),
				Page.PAGE) ? Integer.valueOf((String) candidManager
				.getParamValue(getParamMap(), Page.PAGE)) : 1);// 查询页数
		this.candidPage = candidManager.findCandids(candidPage);
		super.setPageInfo(candidPage);
		return SUCCESS;
	}

	public String add() {
		candid = (getId() != null) ? this.candidManager.get(getId()) : null;
		return "add";
	}

	public String save() {
		candid = this.candidManager.createCandid(candid);
		return "toindex";
	}

	/*************** getter and setter ***********************/
	public Candid getCandid() {
		return candid;
	}

	public void setCandid(Candid candid) {
		this.candid = candid;
	}

	public Page<Candid> getCandidPage() {
		return candidPage;
	}

	public void setCandidPage(Page<Candid> candidPage) {
		this.candidPage = candidPage;
	}

}
